package test;

import com.grt192.core.RobotModel;
/**
 * Simulates the model in movement, assumes perfect movement.
 * @author Vikram, Cody
 *
 */
public class ModelSimulator extends RobotModel implements Runnable {
	protected boolean isMoving;
	private static long SLEEP_TIME = 500;
	protected double speed;
	protected double distance;
	protected double currentDistance;

	public ModelSimulator() {
		isMoving = false;
		currentDistance = 0;
	}

	public void run() {
		while (true) {
			//System.out.println(isMoving);
			while (isMoving && currentDistance < distance) {
				//System.out.println("moving");
				currentDistance += speed;
				x += speed * Math.cos(Math.toRadians(90-heading));
				y += speed * Math.sin(Math.toRadians(90-heading));
				notifyListeners();
				try {
					Thread.sleep(SLEEP_TIME);
				} catch (Exception e) {
					e.printStackTrace();
				}
				if(!(currentDistance<distance)) {
					isMoving=false;
					currentDistance=0;
				}
			}
			try {
				Thread.sleep(SLEEP_TIME);
			} catch (Exception ex) {
				ex.printStackTrace();
			}
		}
	}

	public void moveTo(double r, double theta, double s) {
		System.out.println("moving");
		heading = theta;
		distance = r;
		speed = s*20;
		isMoving = true;
	}

	public void stop() {
		isMoving = false;
	}

	public void fire() {

	}

	public void toggleArm() {

	}

	public void getStatus() {

	}
}